package com.frank.controller;


import com.frank.dto.CommonListDto;
import com.frank.dto.PushDto;
import com.frank.dto.JsonResult;
import com.frank.dto.QueryPageDto;
import com.frank.model.Recommend;
import com.frank.service.PushManageService;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/recruit")
public class PushManageController {
    @Resource
    private PushManageService pushManageService;

    @RequestMapping(value = "/getPushList", method = RequestMethod.POST)
    public JsonResult<?> getPushList(@RequestBody QueryPageDto queryPageDto) {
        CommonListDto commonListDto = pushManageService.getPushList(queryPageDto);
        return new JsonResult<>(200,"获得内推列表成功",commonListDto);
    }

    @Transactional
    @RequestMapping(value = "/addPush", method = RequestMethod.POST)
    public JsonResult<?> addPush(@RequestBody PushDto pushDto) {
        if (pushManageService.addPush(pushDto)){
            return new JsonResult<>(200,"新增内推成功");
        }else {
            return new JsonResult<>(500,"新增内推失败");
        }
    }

    @Transactional
    @RequestMapping(value = "/modifyPush", method = RequestMethod.POST)
    public JsonResult<?> modifyPush(@RequestBody Recommend recommend) {
        if (pushManageService.modifyPush(recommend)){
            return new JsonResult<>(200,"修改内推成功");
        }else {
            return new JsonResult<>(500,"修改内推失败");
        }
    }

    @Transactional
    @RequestMapping(value = "/deletePush", method = RequestMethod.POST)
    public JsonResult<?> deletePush(@RequestParam("pushId") Integer pushId) {
        if (pushManageService.deletePush(pushId)){
            return new JsonResult<>(200,"删除内推成功");
        }else {
            return new JsonResult<>(500,"删除内推失败");
        }
    }

}
